package weaver.ihg.schedule;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.integration.util.JSONUtil;
import weaver.interfaces.schedule.BaseCronJob;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 指数信息管理 uf_DWD_Winning_Metr
 * 指数参数信息管理 uf_DWD_Smart_Deployment_Reference
 * 智能部署清单 uf_znbsqd
 * <p>
 * <p>
 * //2024-10-17 酒店任务类型+酒店任务标题放到智能部署清单列表中，查询。
 * 酒店任务类型=rsia 表中的接收人是什么岗位来判断。
 * 生成高风险指数信息管理→任务合并→查智能填表偏好生成任务状态字段
 */
public class CreateHighRiskTaskCron extends BaseCronJob {
//    private Integer zhishuCreateOrUpdate;//指数结果判断，1=创建时间，0=更新时间
//
//    public Integer getZhishuCreateOrUpdate() {
//        return zhishuCreateOrUpdate;
//    }
//    private Integer canshuCreateOrUpdate;//指数参数结果判断，1=创建时间，0=更新时间
//
//    public Integer getCanshuCreateOrUpdate() {
//        return canshuCreateOrUpdate;
//    }
//
//    public void setCanshuCreateOrUpdate(Integer canshuCreateOrUpdate) {
//        this.canshuCreateOrUpdate = canshuCreateOrUpdate;
//    }
//
//    public void setZhishuCreateOrUpdate(Integer zhishuCreateOrUpdate) {
//        this.zhishuCreateOrUpdate = zhishuCreateOrUpdate;
//    }
//
//    private Integer addDays;//放多少天的指数数据插入到任务详情里面。配置90为3个月初始值
//
//    public Integer getAddDays() {
//        return addDays;
//    }
//
//    public void setAddDays(Integer addDays) {
//        this.addDays = addDays;
//    }

    private String mOduleSql;//模板冲突匹配sql

    public String getmOduleSql() {
        return mOduleSql;
    }

    public void setmOduleSql(String mOduleSql) {
        this.mOduleSql = mOduleSql;
    }

    /**
     * 配置查询高风险表sql语句
     * select ufmd.id,ufmd.sfgfx,ufmd.fxzck,ufmd.INNCODE,ufmd.MTRX,ufmd.yrmtnbr,ufmd.Scenario,ufmd.MTDTRGT,ufmd.MTDResult,ufmd.YTDTRGT,ufmd.YTDResult,ufmd.RiskValue,ufmd.exclusion,ufmd.outbound,ufmd.pc,ufmd.qrzt
     * ,ufsetting.znbscjgw,ufsetting.znbssjgw,ufsetting.znbscsgw
     * from uf_DWD_Smart_Deployment_Reference ufmd left join  uf_indexsetting ufsetting on ufsetting.zsmc=ufmd.id where ufmd.sfgfx=0 and ufmd.qrzt=1 and ufmd.yrmtnbr=?
     */
    private String findOrainSqlStr;

    public String getFindOrainSqlStr() {
        return findOrainSqlStr;
    }

    public void setFindOrainSqlStr(String findOrainSqlStr) {
        this.findOrainSqlStr = findOrainSqlStr;
    }

    private String filedName;//根据月份版本字段，配置月份版本字段的数据库字段名字

    public String getFiledName() {
        return filedName;
    }

    public void setFiledName(String filedName) {
        this.filedName = filedName;
    }

    public static void main(String[] args) {
        String str="jdmc,jddm,zszs,rwbt,cjgwry,sjgwry,csgwry,dymb,rwlx,sftxrwjbxx,sftxrwnr,znbszt,rwhdlx,xscfj,rwdqsj,rwnr";
        System.out.println(str.split(",").length);
//        String format = DateUtil.format(LocalDateTime.now(), "yyyy-MM");
//        System.out.println(format);
//
//        String str="1,2,3,";
//        str=str.substring(0,str.lastIndexOf(","));
//        System.out.println(str);
//        int []cjIntArray=new int[2];
//        cjIntArray[0]=1;
//        cjIntArray[1]=2;
//       String complexKey= StrUtil.join(",",cjIntArray);
//        System.out.println(complexKey);
//        List<String> stringList = Arrays.asList("1", "2", "3");
//        stringList.forEach(s -> {
//            if (s.equals("2")) {
//                return;
//            }
//            System.out.println(s);
//        });

        //获取前三个月时间字符串测试代码
//        DateTime dateTime= DateUtil.offset(DateTime.now(), DateField.DAY_OF_MONTH,-30);
//        System.out.println(dateTime);
//        String findSql = " select * from (select (select zszslx from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as zszslx," +
//                "(select znbscjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscjgw," +
//                "(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbssjgw," +
//                "(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscsgw," +
//                " ufmd.id as id,ufmd.yrmtnbr as YTMR,ufmd.INNCODE,ufmd.MTRX,ufmd.yrmtnbr,ufmd.csmc,ufmd.qrzt," +
////                "ufmd.exclusion,ufmd.outbound,ufmd.pc," +
////                ",ufsetting.znbscjgw,ufsetting.znbssjgw,ufsetting.znbscsgw," +
//                "(select utd.MTDTRGT from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as MTDTRGT" +
//                ",(select utd.MTDResult from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as MTDResult" +
//                ",(select utd.YTDTRGT from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as YTDTRGT" +
//                ",(select utd.YTDResult from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as YTDResult" +
////                ",(select MTDResult from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX  order by modedatacreatedate,pc desc  limit 0,1) as MTDResult" +
////                ",(select YTDTRGT from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc  limit 0,1) as YTDTRGT" +
////                ",(select YTDResult from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc  limit 0,1) as YTDResult" +
//                ",(select utd.Exclusion from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as Exclusion" +
//                ",(select utd.outbound from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as outbound" +
//                ",(select utd.sfgfx from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.MTRX=utd.MTRX order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as sfgfx" +
//
////                ",(select Exclusion from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc  limit 0,1) as Exclusion" +
////                ",(select outbound from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc  limit 0,1) as outbound" +
////                ",(select pc from uf_DWD_Winning_Metr where yrmtnbr=ufmd.yrmtnbr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc  limit 0,1) as pc" +
//                ",ufmd.pc"+
//                ",ufmd.ydmb,ufmd.ydjg as ydjg,ufmd.ydyz as ydyz,ufmd.ndmb as ndmb,ufmd.ndjg as ndjg,ufmd.ndyz as ndyz"+
//                " from uf_DWD_Smart_Deployment_Reference ufmd left join  uf_indexsetting ufsetting on ufsetting.zsmc=ufmd.id  and ufmd.qrzt=1 and ufmd.yrmtnbr=?" +
////                " and sfcg <> 0 and  sfyfs <> 0" +
//                " ) as t1 where t1.sfgfx=0";
//        String format = DateUtil.format(LocalDateTime.now(), "yyyy-MM");
//        System.out.println(findSql.replace("?",format)+";");
//                DateTime dateTime= DateUtil.offset(DateTime.now(), DateField.MINUTE,-2);
//                String dateTime2=DateUtil.now();
//        System.out.println("dateTime2-->"+dateTime2+"===>datTime===>"+dateTime);
//       String timeStr=DateUtil.format(LocalDateTime.now(),"yyyy-MM");
//        System.out.println(timeStr);
//        DateTime dateTime= DateUtil.offset(DateTime.now(), DateField.MINUTE,-2);
//        String format = DateUtil.format(dateTime, "HH:mm:ss");
//        System.out.println(format);
//        DateTime dateTime= DateUtil.offset(DateTime.now(), DateField.DAY_OF_MONTH,-30);
//        System.out.println(dateTime);
    }

    public void complexStringKeyReturn(Map<String, Boolean> resultMap, Map itemData) {
        String compleKey = "";
        String cjrStr = (String) itemData.get("znbscjgw");//创建人
        String sjrStr = (String) itemData.get("znbssjgw");//收件人
        if (cjrStr != null && !cjrStr.equals("")) {
            String[] cjrStrArray = cjrStr.split(",");
            int[] cjIntArray = new int[cjrStrArray.length];
            for (int j = 0; j < cjrStrArray.length; j++) {
                cjIntArray[j] = Integer.parseInt(cjrStrArray[j]);
            }
            Arrays.sort(cjIntArray);//从小到大数组 ，数字排序
            compleKey = StrUtil.join(",", cjIntArray);
        }
        String complexTwo = "";
        if (sjrStr != null && !sjrStr.equals("")) {
            String[] sjrStrArray = sjrStr.split(",");
            int[] sjrIntArray = new int[sjrStrArray.length];
            for (int j = 0; j < sjrIntArray.length; j++) {
                sjrIntArray[j] = Integer.parseInt(sjrStrArray[j]);
            }
            Arrays.sort(sjrIntArray);//从小到大数组 ，数字排序
            complexTwo = StrUtil.join(",", sjrIntArray);
        }
        resultMap.put(itemData.get("INNCODE") + "_" + compleKey + complexTwo, compleKey.equals(complexTwo));
    }

    public String complexStringKeyReturnTwo(Map itemData) {
        String compleKey = "";
        String cjrStr = (String) itemData.get("znbscjgw");//创建人
        String sjrStr = (String) itemData.get("znbssjgw");//收件人
        if (cjrStr != null && !cjrStr.equals("")) {
            String[] cjrStrArray = cjrStr.split(",");
            int[] cjIntArray = new int[cjrStrArray.length];
            for (int j = 0; j < cjrStrArray.length; j++) {
                cjIntArray[j] = Integer.parseInt(cjrStrArray[j]);
            }
            Arrays.sort(cjIntArray);//从小到大数组 ，数字排序
            compleKey = StrUtil.join(",", cjIntArray);
        }
        String complexTwo = "";
        if (sjrStr != null && !sjrStr.equals("")) {
            String[] sjrStrArray = sjrStr.split(",");
            int[] sjrIntArray = new int[sjrStrArray.length];
            for (int j = 0; j < sjrIntArray.length; j++) {
                sjrIntArray[j] = Integer.parseInt(sjrStrArray[j]);
            }
            Arrays.sort(sjrIntArray);//从小到大数组 ，数字排序
            complexTwo = StrUtil.join(",", sjrIntArray);
        }
        return itemData.get("INNCODE") + "_" + compleKey + complexTwo;
    }
    public void excuteSupporetRole( StringBuilder cjRHrmresouce,BaseBean baseBean,Integer inncodeID,StringBuilder znbscjgwStr,String filedName,String tableName){
//        String sqluf_hotelpositions="select wxid from uf_Master_Hotel_Role where inncode="+inncodeID+" and "+Util.getSubINClause(znbscjgwStr.toString(),"hotelrole","in");//中心岗位的数据,酒店岗位的数据
        String sqluf_hotelpositions="select wxid from "+tableName+" where inncode="+inncodeID+" and "+Util.getSubINClause(znbscjgwStr.toString(),filedName,"in");//中心岗位的数据,酒店岗位的数据
        baseBean.writeLog("sqluf_hotelpositions=====>"+sqluf_hotelpositions);
        RecordSet recordSetCj=new RecordSet();
        recordSetCj.execute(sqluf_hotelpositions);
//        StringBuilder cjRHrmresouce=new StringBuilder();
        while (recordSetCj.next()){
            RecordSet recordSetPeoPle=new RecordSet();
            recordSetPeoPle.execute("select id from hrmresource where loginid='"+recordSetCj.getString("wxid")+"'");
            if (recordSetPeoPle.next()){
                cjRHrmresouce.append(recordSetPeoPle.getInt("id"));
            }
        }
    }


    public  void cmpleteMap( Map<String, Object> mapOneDataMap,RecordSet recordSet1){
//                mapOneDataMap.put("fxzck",recordSet.getDouble("fxzck"));//风险值参考

        mapOneDataMap.put("sfcg", recordSet1.getInt("sfcg"));//是否草稿 0:是,1:否
        mapOneDataMap.put("sfyfs", recordSet1.getInt("sfyfs"));//是否已发送,0:已发送,1:未发送
        mapOneDataMap.put("fxzck", recordSet1.getDouble("fxzck"));//风险值参考
        mapOneDataMap.put("INNCODE", recordSet1.getInt("INNCODE"));//酒店代码
        mapOneDataMap.put("MTRX", recordSet1.getInt("MTRX"));//指数名称
        mapOneDataMap.put("YR_MT_NBR", recordSet1.getString("YR_MT_NBR"));//YR_MT_NBR
        mapOneDataMap.put("Scenario", recordSet1.getInt("Scenario"));//参数名称
        mapOneDataMap.put("MTDTRGT", recordSet1.getInt("MTDTRGT"));//月度目标
        mapOneDataMap.put("MTDResult", recordSet1.getDouble("MTDResult"));//月度结果
        mapOneDataMap.put("YTDTRGT", recordSet1.getDouble("YTDTRGT"));//年度目标
        mapOneDataMap.put("YTDResult", recordSet1.getDouble("YTDResult"));//年度结果
        mapOneDataMap.put("RiskValue", recordSet1.getDouble("RiskValue"));//风险值
        mapOneDataMap.put("Exclusion", recordSet1.getString("Exclusion"));//Exclusion
        mapOneDataMap.put("outbound", recordSet1.getString("outbound"));//outbound
        mapOneDataMap.put("pc", recordSet1.getDouble("pc"));//批次
        mapOneDataMap.put("qrzt", recordSet1.getInt("qrzt"));//确认状态
        mapOneDataMap.put("ydmb", recordSet1.getDouble("ydmb"));//月度目标
        mapOneDataMap.put("ydjg", recordSet1.getDouble("ydjg"));//月度结果
        mapOneDataMap.put("ndmb", recordSet1.getDouble("ndmb"));//年度目标
        mapOneDataMap.put("ndjg", recordSet1.getDouble("ndjg"));//年度结果
        mapOneDataMap.put("znbscjgw", recordSet1.getString("znbscjgw"));//rasi表里面的创建人//(select znbscjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscjgw,
        mapOneDataMap.put("znbssjgw", recordSet1.getString("znbssjgw"));//rasi表里面的收件人//(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbssjgw,
    }

    @Override
    public void execute() {

        //select (select zszslx from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as zszslx,(select znbscjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscjgw,(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbssjgw, ufmd.id as id,ufmd.yrmtnbr as YTMR,ufmd.INNCODE,ufmd.MTRX,ufmd.yrmtnbr,ufmd.csmc,ufmd.ydmb,ufmd.ydjg,ufmd.ndmb,ufmd.ndjg,ufmd.exclusion,ufmd.outbound,ufmd.pc,ufmd.qrzt,ufsetting.znbscjgw,ufsetting.znbssjgw,ufsetting.znbscsgw,(select MTDTRGT from uf_DWD_Winning_Metr where yrmtnbr=ufmd.ytmr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX  order by modedatacreatedate,pc desc limit 0,1) as MTDTRGT,(select MTDResult from uf_DWD_Winning_Metr where yrmtnbr=ufmd.ytmr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX  order by modedatacreatedate,pc desc limit 0,1) as MTDResult,(select YTDTRGT from uf_DWD_Winning_Metr where yrmtnbr=ufmd.ytmr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX  order by modedatacreatedate,pc desc limit 0,1) as YTDTRGT,(select YTDResult from uf_DWD_Winning_Metr where yrmtnbr=ufmd.ytmr and ufmd.INNCODE=INNCODE and utmd.MTRX=MTRX order by modedatacreatedate,pc desc limit 0,1) as YTDResult,ufmd.ydmb as ydmb,ufmd.ydjg as ydjg,ufmd.ydyz as ydyz,ufmd.ndmb as ndmb,ufmd.ndjg as ndjg,ufmd.ndyz as ndyz from uf_DWD_Smart_Deployment_Reference ufmd left join  uf_indexsetting ufsetting on ufsetting.zsmc=ufmd.id where ufmd.sfgfx=0 and ufmd.qrzt=1 and ufmd.yrmtnbr='2024-11' and sfcg <> 0 and  sfyfs <> 0
        BaseBean baseBean = new BaseBean();
//    baseBean.writeLog("filedName===>" + filedName + "====>CreateHighRiskTaskCron===>" + findOrainSqlStr);
        baseBean.writeLog("intoThisPage====>createHighCron.jsping.....");
        RecordSet recordSet = new RecordSet();

        String format = DateUtil.format(LocalDateTime.now(), "yyyy-MM");
        //查询出来 指数信息基础表 uf_DWD_Winning_Metr 的字段值，是否超过阀值
        String andMTRSTR="and utmd11.MTRX=utd.MTRX ";
        andMTRSTR="";
        String findSql ="select * from (select (select zszslx from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as zszslx," +
                "(select znbscjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscjgw," +
                "(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbssjgw," +
                "(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscsgw, ufmd.id as id,ufmd.yrmtnbr as YTMR," +
                "ufmd.INNCODE,ufmd.MTRX,ufmd.yrmtnbr,ufmd.csmc,ufmd.qrzt,(select utd.MTDTRGT from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference" +
                " utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.qrzt=1 order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as MTDTRGT," +
                "(select utd.MTDResult from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 " +
                "where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.qrzt=1  order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as MTDResult," +
                "(select utd.YTDTRGT from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.qrzt=1  order by utd.modedatacreatedate,utd.pc desc  " +
                "limit 0,1) as YTDTRGT,(select utd.YTDResult from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 " +
                "where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE and utmd11.qrzt=1  order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as YTDResult," +
                "(select utd.Exclusion from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE  " +
                "and utmd11.qrzt=1 order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as Exclusion,(select utd.outbound from uf_DWD_Winning_Metr utd , " +
                "uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and utmd11.INNCODE=utd.INNCODE  and utmd11.qrzt=1 order by utd.modedatacreatedate,utd.pc desc  " +
                "limit 0,1) as outbound,(select utd.sfgfx from uf_DWD_Winning_Metr utd , uf_DWD_Smart_Deployment_Reference utmd11 where utd.yrmtnbr=utmd11.yrmtnbr and " +
                "utmd11.INNCODE=utd.INNCODE  and utmd11.qrzt=1 order by utd.modedatacreatedate,utd.pc desc  limit 0,1) as sfgfx,ufmd.pc,ufmd.ydmb,ufmd.ydjg as ydjg,ufmd.ydyz as " +
                "ydyz,ufmd.ndmb as ndmb,ufmd.ndjg as ndjg,ufmd.ndyz as ndyz from uf_DWD_Smart_Deployment_Reference ufmd  where ufmd.qrzt=1 and ufmd.yrmtnbr=? and ufmd.qrzt=1 ) as " +
                "t1 where t1.sfgfx=0";


        findSql="select  *" +
//                "(select znbscjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbscjgw," +
//                "(select znbssjgw from uf_indexsetting where zsmc=ufmd.MTRX limit 0,1) as znbssjgw," +
                " from uf_gfxzsxxgl ufmd where  1=1 and sfcg is null or sfcg=1 and  sfyfs is null or sfyfs=1";//0=已发送，1:未发送
//    if (StrUtil.isNotBlank(findOrainSqlStr)) {
//        findSql = findOrainSqlStr;
//    }
        baseBean.writeLog("foramt===>"+format+"===>-----CreateHighRiskTaskCron Excute==>" + "===>findSql===>" + findSql);
        recordSet.execute(findSql);
        //高风险插入sql
//    String insertHigRishTableSql = "insert into uf_gfxzsxxgl (INNCODE,MTRX,yrmtnbr,Scenario,MTDTRGT,ydmb,MTDResult,ydjg,YTDTRGT,ndmb,YTDResult,ndjg,exclusion,outbound,pc,qrzt,RiskValue) values(?," +
//            "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//    baseBean.writeLog("insertHigRishTableSql====>" + insertHigRishTableSql);
//    List<List> params = new ArrayList<>();
        List<Map<String, Object>> highRiskDataList = new ArrayList<>();
        while (recordSet.next()) {
            baseBean.writeLog("id===>"+recordSet.getInt("id")+"======>intoRecosetHgisFor===>"+"Exclusion===>"+recordSet.getString("Exclusion")+"===>"+"====>outbound===>"+recordSet.getString("outbound"));
            if("1".equals(recordSet.getString("Exclusion"))||"1".equals(recordSet.getString("outbound"))){
                continue;
            }
            Map<String, Object> mapOneDataMap = new HashMap<>();
//              cmpleteMa
            cmpleteMap(mapOneDataMap,recordSet);
            highRiskDataList.add(mapOneDataMap);//此处要补充任务类型的处理
//            List<Object> beanParams = new ArrayList<>();
////                beanParams.add(recordSet.getDouble("fxzck"));//风险值参考
//            beanParams.add(recordSet.getInt("INNCODE"));//酒店代码
//            beanParams.add(recordSet.getInt("MTRX"));//指数名称
//            beanParams.add(recordSet.getInt("Scenario"));//参数名称
//            beanParams.add(recordSet.getString("yrmtnbr"));//yrmtnbr
//            beanParams.add(recordSet.getDouble("MTDTRGT"));//月度目标
//            beanParams.add(recordSet.getDouble("ydmb"));//月度目标
//            beanParams.add(recordSet.getDouble("MTDResult"));//月度结果
//            beanParams.add(recordSet.getDouble("ydjg"));//月度结果
//            beanParams.add(recordSet.getDouble("YTDTRGT"));//年度目标
//            beanParams.add(recordSet.getDouble("ndmb"));//年度目标
//            beanParams.add(recordSet.getDouble("YTDResult"));//年度结果
//            beanParams.add(recordSet.getDouble("ndjg"));//年度结果-为参数的时候
//            beanParams.add(recordSet.getString("exclusion"));//Exclusion
//            beanParams.add(recordSet.getString("outbound"));//Outbound
//            beanParams.add(recordSet.getString("pc"));//批次
//            beanParams.add(recordSet.getInt("qrzt"));//确认状态
//            beanParams.add(recordSet.getDouble("RiskValue"));//风险值
//            params.add(beanParams);



        }


        baseBean.writeLog("highRiskDataList高风险数据，查询结果为111111111===>" + highRiskDataList.size());
//    baseBean.writeLog("params==>插入高风险数据data+==>sql===>" + insertHigRishTableSql + "====>" + JSONUtil.toJSONString(params));
//    recordSet.executeBatchSql(insertHigRishTableSql, params);
        //对高风险数据数据，进行合并去生成 智能部署清单列表的数据，查询智能部署清单列表，同一个指数对应的rasi 表里面的创建人与接收人完全一致，进行合并。
//    RecordSet recordSet1=new RecordSet();
//    LocalDateTime nowTime=LocalDateTime.now();
//    String timeStr=DateUtil.format(nowTime,"yyyy-MM");
//    String formatTwo = DateUtil.format(nowTime, "HH:mm:ss");
//    DateTime dateTime= DateUtil.offset(DateTime.now(), DateField.MINUTE,-2);
//    String formatTwoAfter = DateUtil.format(dateTime, "HH:mm:ss");
//    baseBean.writeLog("timeStr===>"+timeStr+"===>formatTwo===>"+formatTwo+"===>formatTwoAfter==>"+formatTwoAfter);
////        System.out.println(format);
//    recordSet1.executeQuery("select * from uf_gfxzsxxgl  where modedatacreatedate=?  and sfcg" +" <> 0 and  sfyfs <> 0",timeStr);
//    highRiskDataList.clear();
//    while (recordSet.next()){
////        Map<String, Object> mapOneDataMap = new HashMap<>();
////        cmpleteMap(mapOneDataMap,recordSet1);
//        highRiskDataList.add(mapOneDataMap);//此处要补充任务类型的处理
//    }
        Map<String, Boolean> keyItemMap = new HashMap<>();
        Map<String, List<Map<String, Object>>> comleteList = new HashMap<>();
        for (int i = 0; i < highRiskDataList.size(); i++) {
            Map itemData = highRiskDataList.get(i);
            baseBean.writeLog("itemDataBefore===>"+JSONUtil.toJSONString(itemData));
            complexStringKeyReturn(keyItemMap, itemData);//获取到组合key，对应是否相等
            baseBean.writeLog("itemDataEndkeyItemMap===>"+JSONUtil.toJSONString(itemData));
            String compleKeyValue = complexStringKeyReturnTwo(itemData);//获取到组合key
            baseBean.writeLog("compleKeyValue====>"+compleKeyValue);
//            if(compleKey){
//                itemData.put("rwlx",1);//酒店任务
//            }else{
//                itemData.put("rwlx",0);//大区任务
//            }
            baseBean.writeLog("comleteList=======>"+JSONUtil.toJSONString(comleteList));
            baseBean.writeLog("keyItemap.containsKeyValue===>"+keyItemMap.get(compleKeyValue)+"====>!containKey"+!comleteList.containsKey(compleKeyValue));

            baseBean.writeLog("keyItemMap.get(compleKeyValue) ===>"+keyItemMap.get(compleKeyValue) +"=====>comleteList.containsKey(compleKeyValue)====>"+comleteList.containsKey(compleKeyValue));

            if (keyItemMap.get(compleKeyValue) && !comleteList.containsKey(compleKeyValue)) {//当组合key 接收人，收件人相等，第一次遍历时需要进行统一只新增一次，取出itemData新增即可;
                //map循环是hash排序的，itemdata是map的其中一个元素。
                //合并新增到智能部署一行中
                List<Map<String, Object>> itemListData = new ArrayList<>();
                itemListData.add(itemData);
                //新增完以后标记到List集合中
                comleteList.put(compleKeyValue, itemListData);
                baseBean.writeLog("oneForCompleteList==>"+JSONUtil.toJSONString(comleteList));
            } else if (keyItemMap.get(compleKeyValue) && comleteList.containsKey(compleKeyValue)) {
                List<Map<String, Object>> itemListData = comleteList.get(compleKeyValue);
                baseBean.writeLog("twoForItemListData===>"+JSONUtil.toJSONString(itemListData)+"======>compleKeyValue======>"+compleKeyValue);
                itemListData.add(itemData);
                comleteList.put(compleKeyValue, itemListData);
                baseBean.writeLog("twoForItemListDataAfter=======>"+itemListData);
            } else {
                baseBean.writeLog("elseIntoTHis====>");
                List<Map<String, Object>> itemListData = new ArrayList<>();
                baseBean.writeLog("itemData====>"+itemListData);
                itemListData.add(itemData);
                //新增完以后标记到List集合中
                comleteList.put(compleKeyValue, itemListData);
            }

        }


        baseBean.writeLog("taskDataList===>" + JSONUtil.toJSONString(comleteList));
        List<List> realParams = new ArrayList<>();
//        String filedNameStr = "jdmc,jddm,zszs,rwbt,cjgwry,sjgwry,csgwry,dymb,rwlx,sftxrwjbxx,sftxrwnr,znbszt,rwhdlx,xscfj,rwdqsj,rwnr";//酒店名称，酒店代码，致胜指数,任务标题,创建岗位人员,	抄送岗位人员,	收件岗位人员,是否基本信息填写，是否基本内容填写,智能部署状态,任务互动类型,	需上传附件,任务到期时间,任务内容
        String filedNameStr="cjgw,sjgw,CsgW,cigwry";
        List fileNameStrList = Arrays.asList(filedNameStr.split(","));
        String insertTaskSql = "insert into uf_znbsqd (" + filedNameStr + ") values(?,?,?,?) ";//插入到智能部署表中
        List<String> inncodeList = new ArrayList<>();
        if(highRiskDataList==null||highRiskDataList.size()==0){
            return;
        }
        for (Map<String, Object> stringObjectMap : highRiskDataList) {
            inncodeList.add(stringObjectMap.get("INNCODE")+"");
        }

        Map inncodeMapData = getHotelNameMap(inncodeList);
        Map uf_phszListMapData = getuf_phszList(inncodeList);//根据酒店代码找到所有的偏好设置
        comleteList.forEach((k, v) -> {
            Integer inncodeID = Integer.parseInt(k.split("_")[0]);
            Map ufPhMapDataMap = (Map) uf_phszListMapData.get(inncodeID);//获取偏好设置每一项
            if (ufPhMapDataMap!=null&&(ufPhMapDataMap.get("cjrw") == null || !((ufPhMapDataMap.get("cjw") + "").equals("1")))) {//创建任务没勾选的情况下,此智能部署清单不生成
                return;
            }

            List<Object> beanParamsTwo = new ArrayList<>();
            //酒店指数代码合并，
            StringBuilder hotelStr = new StringBuilder();
            //致胜指数合并,
            StringBuilder zszsStr = new StringBuilder();
            //所有的raisvAlue 集合值
            Map<String,Double> rasiValueList = new HashMap<>();
            for (Map<String, Object> stringObjectMap : v) {
                hotelStr.append(stringObjectMap.get("INNCODE")).append(",");
                zszsStr.append(stringObjectMap.get("MTRX")).append(",");
                rasiValueList.put( stringObjectMap.get("MTRX")+"",Double.parseDouble(stringObjectMap.get("RiskValue") == null ? "0" : stringObjectMap.get("RiskValue")+""));
            }

            //风险系统 字段待确认 已确认不用了
            if (hotelStr.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("hotelStrBerfore===>" + hotelStr);
                hotelStr = new StringBuilder(hotelStr.substring(0, hotelStr.lastIndexOf(",")));
                baseBean.writeLog("hotelStrEndAfter===>" + hotelStr);
            }
            if (zszsStr.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("zszsStrBerfore===>" + hotelStr);
                zszsStr = new StringBuilder(zszsStr.substring(0, zszsStr.lastIndexOf(",")));
                baseBean.writeLog("zszsStrEndAfter===>" + zszsStr);
            }
            //酒店名字集合合并
            List<List> hotelList = new ArrayList<>();
            String[] split = hotelStr.toString().split(",");
            for (String s : split) {
                List<Object> itemList=new ArrayList<>();
                itemList.add(s);
                hotelList.add(itemList);
            }
            String hotelInfoSqlListSql = "select * from uf_hotelinfo where "+Util.getSubINClause(StrUtil.join(",",hotelList),"id","in");
            RecordSet hotleINfORecord = new RecordSet();
            baseBean.writeLog("hotelInfoSqlListSql=======>" + hotelInfoSqlListSql);
            boolean htoelFindData = hotleINfORecord.execute(hotelInfoSqlListSql);
            StringBuilder htoelNameStr = new StringBuilder();
            while (hotleINfORecord.next()) {
                htoelNameStr.append(hotleINfORecord.getString("hotelnamezh"));
            }

            beanParamsTwo.add(htoelNameStr);//酒店名称
            beanParamsTwo.add(hotelStr);//酒店指数代码
            beanParamsTwo.add(zszsStr);//致胜指数
            String selectuf_systemconfig = "select paramvalue from uf_systemconfig where uuid='hotle_title'";//找到开发系统配置表中的任务标题配置值
            RecordSet ufSYsteRecordSet = new RecordSet();
            ufSYsteRecordSet.execute(selectuf_systemconfig);
            Map ytmR = new HashMap<>();
            //问题:取哪个指数的YR_MT_NBR
            if (v.size() > 0) {
                ytmR = v.get(0);
            }
            if (ufSYsteRecordSet.next()) {
                beanParamsTwo.add(ufSYsteRecordSet.getString("paramvalue") + "#" + ((ytmR.get("YR_MT_NBR") == null ? "" : ytmR.get("YR_MT_NBR"))) + "#Review");//rwbt 任务标题 要取指数对应的模板库里面的符合规则的，取出来的模板。
            } else {
                beanParamsTwo.add("" + "#" + ((ytmR.get("YR_MT_NBR") == null ? "" : ytmR.get("YR_MT_NBR"))) + "#Review");//酒店任务标题
            }
            //beanParamsTwo.add(1); //任务类型,等生成以后，根据收件人去酒店岗位表找，和中心岗位表找
            baseBean.writeLog("htoelFindData========>11111111" + htoelFindData);
//            recordSet.executeSql("select isremark,isreminded,preisremark,id,groupdetailid,nodeid,
//            (CASE WHEN isremark=9 THEN 0.99 WHEN isremark=11 THEN 0.98 WHEN (isremark=1 and takisremark=2) THEN 0.9 WHEN
//            (preisremark=1 and isremark=2) THEN 1.9 WHEN (isremark=0 and takisremark = -2 and isInMultiTak = 1) THEN 2  ELSE isremark END)
//            orderisremark from workflow_currentoperator where requestid=" + requestid + " and userid=" + userid
//                    + " and usertype=" + usertype + "  and islasttimes = 1 order by orderisremark,id");

            RecordSet recordSet1 = new RecordSet();
            //根据RACI设置制胜指数找出来相应的接收人，生成为创建人， 接收人，抄送人

            //11
//            for (Double aDouble : rasiValueList) {
//                sqlZHishuStr.append(" or fxzmin contact( select xyh from ( select (CASE WHEN xyh=0 THEN u5.fxzmin-").append(aDouble).append(" WHEN xyh=1 THEN '<=' ELSE xyh END) as xyh  from uf_indexsetting u2 where u5.id=id) u3 ) ");
//            }
            //使用程序里面进行判断

            StringBuilder znbscjgwStr = new StringBuilder();//创建人
            StringBuilder znbssjgwwStr = new StringBuilder();//收件人
            StringBuilder znbscsgwwStr = new StringBuilder();//抄送人
            for (Map<String, Object> stringObjectMap : v) {
                double riskValueTtem = Double.parseDouble(stringObjectMap.get("RiskValue") == null ? "0" : stringObjectMap.get("RiskValue") + "");
                String jsonStr="select id,znbscjgw,znbssjgw,znbscsgw,xyh,fxzmin,zsmc,fxzmax from uf_indexsetting  where";
                StringBuilder sqlZHishuStr = new StringBuilder(jsonStr);
                List<List> datas = new ArrayList<>();
                String[] arrayStr = zszsStr.toString().split(",");
                baseBean.writeLog("arrayStr===>" + Arrays.toString(arrayStr) + "===>sqlZHishuStr====>" + sqlZHishuStr);
                for (String s : arrayStr) {
                    List<Object> dataList = new ArrayList<>();
                    dataList.add(s);
                    datas.add(dataList);
                }
                /**
                 * （风险值MIN fxzmin ） （小于号 xyh） 高风险表[高风险值]  （小于号2 xyh2)  (
                 * 风险值MAX
                 *
                 * fxzmax
                 * )
                 */
                baseBean.writeLog("datas===>" + JSONUtil.toJSONString(datas));
                sqlZHishuStr.append(Util.getSubINClause(StrUtil.join(",",datas),"zsmc","in"));
                baseBean.writeLog("sqlZHishuStr===>" + sqlZHishuStr.toString());
                recordSet1.execute(sqlZHishuStr.toString());


                while (recordSet1.next()) {
                    int xyh=recordSet1.getInt("xyh");//小于号，0 :<,1 :<=
                    int xyh2=recordSet1.getInt("xyh2");//小于号2，0 :<,1 :<=
                    if(xyh==0&&recordSet1.getDouble("fxzmin")>=riskValueTtem){
                        continue;
                    }
                    if(xyh==1&&recordSet1.getDouble("fxzmin")>riskValueTtem){
                        continue;
                    }

                    if(xyh2==0&&recordSet1.getDouble("fxzmax")>=riskValueTtem){
                        continue;
                    }
                    if(xyh2==1&&recordSet1.getDouble("fxzmax")>riskValueTtem){
                        continue;
                    }
                    znbscjgwStr.append(recordSet1.getInt("znbscjgw")).append(",");
                    znbssjgwwStr.append(recordSet1.getInt("znbssjgw")).append(",");
                    znbscsgwwStr.append(recordSet1.getInt("znbscsgw")).append(",");
                }

            }
            String sqluf_hotelpositions="select wxid from uf_Master_Hotel_Role where inncode="+inncodeID+" and "+Util.getSubINClause(znbscjgwStr.toString(),"hotelrole","in");//中心岗位的数据,酒店岗位的数据
            baseBean.writeLog("sqluf_hotelpositions=====>"+sqluf_hotelpositions);
            StringBuilder cjRHrmresouce=new StringBuilder();
            excuteSupporetRole(cjRHrmresouce,baseBean,inncodeID,znbscjgwStr,"hotelrole","uf_Master_Hotel_Role");
            excuteSupporetRole(cjRHrmresouce,baseBean,inncodeID,znbscjgwStr,"SupportRole","ODS_Support_Center_Scope");

            if (znbscjgwStr.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("znbscjgwStrBeforfe===>" + znbscjgwStr);
                znbscjgwStr = new StringBuilder(znbscjgwStr.substring(0, znbscjgwStr.lastIndexOf(",")));
                baseBean.writeLog("znbscjgwStrEndAfter===>" + znbscjgwStr);
            }


            if (znbscjgwStr.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("znbscjgwStrBeforfe===>" + znbscjgwStr);
                znbscjgwStr = new StringBuilder(znbscjgwStr.substring(0, znbscjgwStr.lastIndexOf(",")));
                baseBean.writeLog("znbscjgwStrEndAfter===>" + znbscjgwStr);
            }
            if (znbscsgwwStr.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("znbscsgwwStrBeforfe===>" + znbscsgwwStr);
                znbscsgwwStr = new StringBuilder(znbscsgwwStr.substring(0, znbscsgwwStr.lastIndexOf(",")));
                baseBean.writeLog("znbscsgwwStrEndAfter===>" + znbscsgwwStr);
            }
            if (cjRHrmresouce.toString().lastIndexOf(",") != -1) {
                baseBean.writeLog("cjRHrmresouceStrBeforfe===>" + cjRHrmresouce);
                cjRHrmresouce = new StringBuilder(cjRHrmresouce.substring(0, cjRHrmresouce.lastIndexOf(",")));
                baseBean.writeLog("cjRHrmresouceEndAfter===>" + cjRHrmresouce);
            }
            beanParamsTwo.add(znbscjgwStr);//cjgwry 创建岗位人员
            beanParamsTwo.add(znbssjgwwStr);//sjgwry 收件岗位人员
            beanParamsTwo.add(znbscsgwwStr);//csgwry 抄送岗位人员
            beanParamsTwo.add(cjRHrmresouce);//csgwry 创建的人
            baseBean.writeLog("zszsStr111===>"+zszsStr);
//            List<String > reusltModulIds=reusltModulIdsLsit(inncodeMapData,zszsStr,inncodeID,baseBean,null);
//            beanParamsTwo.add(StrUtil.join(",", reusltModulIds));// 调用模板
//            //任务类型
//            beanParamsTwo.add(findAllRevieverLogindEquals(Arrays.asList(znbssjgwwStr.toString().split(","))) ? 1 : 0);//1:酒店任务,0:大区任务
////            beanParamsTwo.add(1);//znbszt 智能部署状态
//            baseBean.writeLog("beanParamsTwo======>" + JSONUtil.toJSONString(beanParamsTwo));
//
//            //进行清空字段值 或者对字段值进行校验
//            String taskBaseInfoStr = "rwbt,rwlx,jdmc,jddm,zszs";//任务标题，任务类型，酒店名称，酒店代码，致胜指数
//            String contentFiledStr = "cjgwry,sjgwry,csgwry";//创建岗位人员,收件岗位人员,抄送岗位人员
//            //偏好设置表中，基本信息的时候，字段值如下:
//            int wirteBaseINfo = 0;//是否填写任务基本信息 是=0，否=1
//            int wirteTaskConten = 0;//是否填写任务内容是=0，否=1
//            if ("1".equals(uf_phszListMapData.get("jbxx") + "")) {//1代表check框勾选了
//
//                String[] taskBaseInfoStrArray = taskBaseInfoStr.split(",");
//                for (int i = 0; i < taskBaseInfoStrArray.length; i++) {
//                    Object o = beanParamsTwo.get(fileNameStrList.lastIndexOf(taskBaseInfoStrArray[i]));
//                    if (o == null) {
//                        wirteBaseINfo = 1;
//                        break;
//                    }
//                }
//            } else {
//                String[] taskBaseInfoStrArray = taskBaseInfoStr.split(",");
//                for (int i = 0; i < taskBaseInfoStrArray.length; i++) {
//                    beanParamsTwo.set(fileNameStrList.lastIndexOf(taskBaseInfoStrArray[i]), null);
//                }
//            }
//            beanParamsTwo.add(wirteBaseINfo);//是否填写了基本信息 下拉框字段值 是=0,否=1
//            //偏好设置表中,任务内容的时候,字段值如下:
//            if ("1".equals(uf_phszListMapData.get("rwnr") + "")) {//1代表check框勾选了
//                String[] contentFiledStrArray = contentFiledStr.split(",");
//                for (int i = 0; i < contentFiledStrArray.length; i++) {
//                    Object o = beanParamsTwo.get(fileNameStrList.lastIndexOf(contentFiledStrArray[i]));
//                    if (o == null) {
//                        wirteTaskConten = 1;
//                        break;
//                    }
//                }
//            } else {
//                String[] contentFiledStrArray = contentFiledStr.split(",");
//                for (int i = 0; i < contentFiledStrArray.length; i++) {
//                    beanParamsTwo.set(fileNameStrList.lastIndexOf(contentFiledStrArray[i]), null);
//                }
//            }
//            beanParamsTwo.add(wirteTaskConten);//是否填写任务内容 是=0，否=1 下拉框字段值
//            if (wirteTaskConten == 0 && wirteBaseINfo == 0) {
//                beanParamsTwo.add(0);//部署状态 0=参数满足,1=不满足,2=部分满足
//            } else if ((wirteBaseINfo == 0) || (wirteTaskConten == 0)) {
//                beanParamsTwo.add(2);//部署状态 0=参数满足,1=不满足,2=部分满足
//            } else {
//                beanParamsTwo.add(1);//部署状态 0=参数满足,1=不满足,2=部分满足
//            }
//            Map onMathRuleMap = matchRuleFirsetModule(reusltModulIds, baseBean);//任务符合的map 字段值
//            baseBean.writeLog("onMathRuleMap======>"+JSONUtil.toJSONString(onMathRuleMap));
//            //rwhdlx,xscfj,rwdqsj,rwnr";//任务互动类型,	需上传附件,任务到期时间,任务内容
//
//            beanParamsTwo.add(onMathRuleMap.get("rwhdlx"));//任务互动类型
//            beanParamsTwo.add(onMathRuleMap.get("xscfj"));//需上传附件
//            beanParamsTwo.add(onMathRuleMap.get("rwdqsj"));//任务到期时间
//            StringBuilder stringBuilder = bulidTaskContent(reusltModulIds);
//            baseBean.writeLog("stringBuilderString===>"+stringBuilder.toString());
//            beanParamsTwo.add(bulidTaskContent(reusltModulIds).toString());//任务内容
            realParams.add(beanParamsTwo);
        });

        baseBean.writeLog("into智能部署清单列表数据===>" + JSONUtil.toJSONString(realParams));
        boolean insetToTaskList = false;
        try {
            insetToTaskList = recordSet.executeBatchSql(insertTaskSql, realParams);
        } catch (Exception e) {
            baseBean.writeLog("eRRor===>"+e.getMessage());
//            e.printStackTrace();
        }

        baseBean.writeLog("insetToTaskList===>" + insetToTaskList);

//        //进行新增明细表1数据,新增明细表2数据；
//        addDetailDataMethod(inncodeMapData,baseBean,inncodeList);
    }
    public void addDetailDataMethod(Map inncodeMapData,BaseBean baseBean,  List<String> inncodeList){
        Map uf_phszListMapData = getuf_phszList(inncodeList);//根据酒店代码找到所有的偏好设置
        RecordSet recordSet=new RecordSet();
        DateTime dateTime=DateUtil.offset(DateTime.now(),DateField.MINUTE,-5);
        String detailSql="select  * from uf_gfxzsxxgl ufmd where  1=1 and sfcg is null or sfcg=1 and  sfyfs is null or sfyfs=1";//0=已发送，1:未发送
        recordSet.execute(detailSql);
        while (recordSet.next()){
            Integer inncodeID = recordSet.getInt("INNCODE");
            Map ufPhMapDataMap = (Map) uf_phszListMapData.get(inncodeID);//获取偏好设置每一项
            if (ufPhMapDataMap.get("cjrw") == null || !((ufPhMapDataMap.get("cjw") + "").equals("1"))) {//创建任务没勾选的情况下,此智能部署清单不生成
                return;
            }
            //致胜指数合并,
            StringBuilder zszsStr = new StringBuilder();
            //所有的raisvAlue 集合值
            Map<String,Double> rasiValueList = new HashMap<>();
            zszsStr.append(recordSet.getInt("MTRX"));
            rasiValueList.put(( recordSet.getInt("MTRX")+""),recordSet.getDouble("RiskValue"));
            reusltModulIdsLsit(inncodeMapData,zszsStr,inncodeID,baseBean,recordSet);
        }


    }
    public List<String> reusltModulIdsLsit(Map inncodeMapData,StringBuilder zszsStr,Integer inncodeID,BaseBean baseBean,RecordSet recordSet){
        //根据酒店代码找到相应的大区。
        List<String> reusltModulIds = new ArrayList<>();
        //根据酒店代码找到所有酒店信息的，大区，品牌，管理模式
        // 指数+大区+品牌+管理模式 找指数库规则表
        RecordSet zhishuRecordSet = new RecordSet();
        Map<String, Object> innCodeMapArgs = (Map<String, Object>) inncodeMapData.get(inncodeID + "");
        if(innCodeMapArgs==null){
            innCodeMapArgs=new HashMap<>();
        }
        String zhishuRecordSetKuSql = "select * from uf_zsk where "+Util.getSubINClause(StrUtil.join(",",Arrays.asList(zszsStr.toString().split(","))),"id","in")+") and region='"+innCodeMapArgs.get("region")+"' and brand='"+innCodeMapArgs.get("brand")+"'";
       baseBean.writeLog("zhishuRecordSetKuSql========>"+zhishuRecordSetKuSql);
        zhishuRecordSet.execute(zhishuRecordSetKuSql);
        List<List> insertZhishuList=new ArrayList<>();
        List<List> insertCanshList=new ArrayList<>();

        String insertZhishuSignleSql="insert into uf_znbsqd_dt1 (yrmtnbr,zsmc,ndjg,mainId) values (?,?,?,?)";
        //yrmtnbr YR_MT_NBR 单行文本框 文本 文本长度:999
        //zsmc 指数名称 浏览按钮 自定义单选 browser.zszs
        //ndjg 年度结果 单行文本框 浮点数 小数点位数:2

        String insertZhishuTwoSql="insert into uf_znbsqd_dt2 (csmc,yrmtnbr,ndyd,csjgz,mainId) values (?,?,?,?,?)";
        // csmc 参数名称 浏览按钮 自定义单选 browser.select_parameter
        //yrmtnbr YR_MT_NBR 单行文本框 文本 文本长度:999
        //ndyd 年度/月度 选择框-下拉框 年度,月度
        //csjgz 参数结果值 单行文本框 浮点数 浮点数 小数点位数:2
        DateTime threeMonthAgo= DateUtil.offset(DateTime.now(), DateField.DAY_OF_MONTH,-90);//前三个月
        DateTime nowTime= DateTime.now();//当前时间
        while (zhishuRecordSet.next()) {
            //匹配原则
            int ppgz = zhishuRecordSet.getInt("ppgz");//0=and ,1=or
            //根据指数找到所有，年度月度值。
            String detailsSql = "select * from uf_zsk_dt1 where mainId=?";
            baseBean.writeLog("detailsSql===>" + detailsSql + "===>mainId==>" + zhishuRecordSet.getInt("zs"));
            RecordSet recordSetDetail = new RecordSet();
            recordSetDetail.executeQuery(detailsSql, zhishuRecordSet.getInt("id"));
            boolean andJudege = false;//and 的时候下面有任意一不符合就=true;
            boolean orJudege1 = false;//or 的时候下面所有不符合就=true;
            List<String> canshIdList = new ArrayList<>();
            RecordSet canshPipei = new RecordSet();
            canshPipei.executeQuery("select csmc from uf_DWD_Smart_Deployment_Reference where INNCODE=?", inncodeID);//找指数参数表里面等于这个酒店代码的，参数ID从才需去模板规则库匹配
            while (canshPipei.next()) {
                canshIdList.add(canshPipei.getInt("csmc") + "");//参数名称
            }
            while (recordSetDetail.next()) {

                if (!canshIdList.contains(recordSetDetail.getInt("cs") + "")) {//获取模板规则库明细里面的参数字段值与，找到对应的指数和酒店代码中的指数参数中的参数id值
                    continue;
                }
                List<Object> paramListObj=new ArrayList<>();
                List<Object> paramListObjTwo=new ArrayList<>();
                String yearSqlValue = "select * from uf_DWD_Winning_Metr where MTRX=" + zhishuRecordSet.getInt("zs");//找到指数管理表中的数据要被比较的值
                String sqlStr = "select lx from uf_parameterinfo where id=?";//lx=0参数，1指数
                RecordSet recordSetDetailSql = new RecordSet();
                recordSetDetailSql.executeQuery(sqlStr,recordSetDetail.getInt("cs"));
                int lxFirst = 3;
                if (recordSetDetailSql.next()) {
                    int lxTwo = recordSetDetailSql.getInt("lx");
                    lxFirst = lxTwo;
                    if (lxTwo == 1) {
                        yearSqlValue = "select * from uf_DWD_Winning_Metr where MTRX=" + zhishuRecordSet.getInt("zs");//找到指数管理表中的数据要被比较的值;
                    } else if (lxTwo == 0) {
                        yearSqlValue = "select * from uf_DWD_Smart_Deployment_Reference where MTRX=" + zhishuRecordSet.getInt("zs");//找到指数参数表中的数据要被比较的值;
                    }
                }
                baseBean.writeLog("yearSqlValue===>" + yearSqlValue);
                RecordSet compareRecordSet = new RecordSet();
                compareRecordSet.execute(yearSqlValue);
                int ndyd = recordSetDetail.getInt("ndyd");//年度=0,1=月度；
                int lx = recordSetDetail.getInt("lx");//年度目标值=0,年度阈值=1,月度目标值=2,月度阈值=3,4=1;//类型
                int gz = recordSetDetail.getInt("gz");//0=>,1=<,2==,
                String jsgs = recordSetDetail.getString("jsgs");//计算公式
//                    Map<Integer,String> paramsTeMap=new HashMap<>();
//                    paramsTeMap.put(0,"YTDTRGT");
//                    paramsTeMap.put(1,"ndjg");
                double z = recordSetDetail.getString("z") == null || recordSetDetail.getString("z").equals("") ? 0 : Double.parseDouble(recordSetDetail.getString("z"));//值
                //找到参数里面的月度阀值和
//                    String befprepareFiledName = paramsTeMap.get(ndyd);
                double compareValue=0;

                double yearOverValue = 0;
                if(compareRecordSet.next()){
                    if(ndyd==0){
                        if (lxFirst == 1) {//指数
                            compareValue= compareRecordSet.getDouble("YTDTRGT");
                         }else {

                        }  compareValue = compareRecordSet.getDouble("ndjg");//年度结果值

                    }else if(ndyd==1){
                        if (lxFirst == 1) {//指数
                            compareValue = compareRecordSet.getDouble("MTDResult");//月度结果

                        } else {
                            compareValue = compareRecordSet.getDouble("ydjg");//月度结果

                        }
                    }
                    if (lx == 0) {
                        if (lxFirst == 1) {//指数
                            yearOverValue = compareRecordSet.getDouble("YTDTRGT");//年度结果
                            //假如在三个月内
                            if(recordSet!=null){
                                Date modedatacreatedate=compareRecordSet.getDate("modedatacreatedate");
                                if(threeMonthAgo.isBefore(modedatacreatedate)&&nowTime.isAfter(threeMonthAgo)){//在三个月时间之后，在当前时间之前的三个月内的数据

                                    paramListObj.add(compareRecordSet.getString("yrmtnbr"));
                                    paramListObj.add(compareRecordSet.getInt("MTRX"));//指数名称
                                    paramListObj.add(compareRecordSet.getDouble("ndmb"));//年度结果
                                    paramListObj.add(recordSet.getInt("id"));//mianID主表id值
                                    insertZhishuList.add(paramListObj);
                                }
                            }
                        } else {
                            yearOverValue = compareRecordSet.getDouble("ndjg");//年度结果值

                            DateTime oneMonthBefore=DateUtil.offset(DateTime.now(), DateField.MONTH, -1);
                            //假如在一个月内
                            if(recordSet!=null){
                                Date modedatacreatedate=compareRecordSet.getDate("modedatacreatedate");
                                if(oneMonthBefore.isBefore(modedatacreatedate)&&nowTime.isAfter(oneMonthBefore)){//在一个月时间之后，在当前时间之前的1个月内的数据

                                    paramListObjTwo.add(compareRecordSet.getInt("csmc"));//参数名称
                                    paramListObjTwo.add(compareRecordSet.getInt("yrmtnbr"));
                                    paramListObjTwo.add(compareRecordSet.getDouble("YTDTRGT"));//年度结果
                                    paramListObjTwo.add(recordSet.getInt("id"));//mianID主表id值
                                    insertCanshList.add(paramListObjTwo);
                                }
                            }
                        }

                    } else if (lx == 1) {
                        if (lxFirst == 1) {//指数
                            yearOverValue = compareRecordSet.getDouble("YTDResult");//年度阈值


                        } else {
                            yearOverValue = compareRecordSet.getDouble("ndyz");//年度阀值

                        }
                    } else if (lx == 2) {
                        if (lxFirst == 1) {//指数
                            yearOverValue = compareRecordSet.getDouble("MTDTRGT");//月度目标
                        } else {
                            yearOverValue = compareRecordSet.getDouble("ydmb");//月度目标
                        }
                    } else if (lx == 3) {
                        if (lxFirst == 1) {//指数
                            yearOverValue = compareRecordSet.getDouble("MTDResult");//月度结果

                        } else {
                            yearOverValue = compareRecordSet.getDouble("ydjg");//月度结果

                        }
                    } else if (lx == 4) {

                        yearOverValue = 1;
                    }
                }

                baseBean.writeLog("gz====>" + gz + "======>yearOverValue===>" + yearOverValue);
                switch (gz) {
                    case 0:
                        if (compareValue <= yearOverValue * z) {
                            andJudege = true;
                            orJudege1 = true;
                        } else {
                            orJudege1 = false;
                        }
                        break;
                    case 1:
                        if (compareValue >= yearOverValue * z) {
                            andJudege = true;
                            orJudege1 = true;
                        } else {
                            orJudege1 = false;
                        }
                        break;
                    case 2:
                        if (compareValue != yearOverValue * z) {
                            andJudege = true;
                            orJudege1 = true;
                        } else {
                            orJudege1 = false;
                        }
                        break;
                    default:
                        break;
                }


            }
            if (andJudege && ppgz == 0) {
                reusltModulIds.add(zhishuRecordSet.getInt("mb") + "");
            }
            if (orJudege1 && ppgz == 1) {
                reusltModulIds.add(zhishuRecordSet.getInt("mb") + "");
            }


        }
        if(recordSet!=null){
            boolean b1= new RecordSet().executeBatchSql(insertZhishuSignleSql, insertZhishuList);
            baseBean.writeLog("b1===>"+b1);
            boolean b2 = new RecordSet().executeBatchSql(insertZhishuTwoSql, insertCanshList);
            baseBean.writeLog("b2===>"+b2);
        }
        return reusltModulIds;
    }
    // 当参数满足一条及以上的规则时，在任务内容中，应按段落堆叠内容话术。
    /**
     * 任务内容堆叠
     *
     * @param dyMouldeIds 调用模板ids
     * @return
     */
    public StringBuilder bulidTaskContent(List<String> dyMouldeIds) {
        StringBuilder stringBuilder = new StringBuilder();

        RecordSet recordSet = new RecordSet();
        String mOduleSql = "select id,rwnr,rwhdlx,xscfj,rwdqsj from uf_mbk where "+Util.getSubINClause(StrUtil.join(",",dyMouldeIds),"id","in");

        BaseBean baseBean=new BaseBean();
        baseBean.writeLog("dyModuleidSql===>"+mOduleSql);
         recordSet.execute(mOduleSql);
        while (recordSet.next()) {
            stringBuilder.append(recordSet.getString("rwnr")).append("\n");//堆叠任务内容
        }
        return stringBuilder;
    }

    /**
     * 找到模板冲突 ，符合规则的那一条 当任务互动类型在不同模板发生冲突时，选择“酒店现场”；当需上传附件发生冲突时，选择“是”；当任务到期日发生冲突时，选择较远的日期
     *
     * @return
     */
    public Map<String, Object> matchRuleFirsetModule(List<String> dyMouldeIds, BaseBean baseBean) {
        Map<String, Object> oneMatchchMap = new HashMap<>();
        RecordSet recordSet = new RecordSet();
//        String mOduleSql="select id,rwnr,rwhdlx,xscfj,rwdqsj from uf_mbk where id in (?) order by xscfj,rwdqsj desc";
        if (StrUtil.isEmpty(mOduleSql)) {
            mOduleSql = "select id,rwnr,rwhdlx,xscfj,rwdqsj from uf_mbk where id in (?) order by xscfj,rwdqsj desc limit 0,1";
        }
        recordSet.executeQuery(mOduleSql, StrUtil.join(",", dyMouldeIds));
        if (recordSet.next()) {
            oneMatchchMap.put("rwnr", recordSet.getString("rwnr"));//任务内容
            oneMatchchMap.put("rwhdlx", recordSet.getInt("rwhdlx"));//0=酒店现场,1=线下讨论
            oneMatchchMap.put("xscfj", recordSet.getInt("xscfj"));//0=是，1=否
            oneMatchchMap.put("rwdqsj", recordSet.getInt("rwdqsj"));//任务到期时间
        }
        baseBean.writeLog("oneMatchMap==>" + JSONUtil.toJSONString(oneMatchchMap));
        return oneMatchchMap;
    }

    /**
     * @param hrmresourseIds 人力资源ids 集合
     * @return
     */
    //找酒店岗位表中的企信id等于此人的loginid;
    public Boolean findAllRevieverLogindEquals(List<String> hrmresourseIds) {
        String findHtoelInfoTable = "SELECT count(1) as countId FROM uf_master_hotel_role WHERE wxid IN ( SELECT t.loginid FROM (SELECT loginid FROM hrmresource where id in (?)) AS t )";
        RecordSet recordSet = new RecordSet();
        recordSet.executeQuery(findHtoelInfoTable, StrUtil.join(",", hrmresourseIds));
        Integer countAll = 0;
        if (recordSet.next()) {
            countAll = recordSet.getInt("countId");
        }
        return countAll > 0;
    }

    //通过map的id找到相应的map
    public Map<String, Object> getMapObject(List<Map<String, Object>> mapList, String id) {
        AtomicReference<Map<String, Object>> result = new AtomicReference<>();
        for (Map<String, Object> stringObjectMap : mapList) {
            stringObjectMap.forEach((k, v) -> {
                if (k.equalsIgnoreCase(id)) {
                    result.set((Map<String, Object>) v);
                }
            });
        }
        return result.get();
    }



    /**
     * 找到酒店代码和酒店类型同一个的，指数集合
     *
     * @param findFiledStr 找的字段名字集合
     * @return
     */

    public List<Object> getBiaojiList(String findFiledStr, String hotelKey, Map<String, List<Map<String, Object>>> taskDataList) {
        List<Object> reusltList = new ArrayList<>();
        taskDataList.forEach((k, v) -> {
            if (hotelKey.equalsIgnoreCase(k.split("_")[0])) {
                for (Map<String, Object> stringObjectMap : v) {
                    reusltList.add(stringObjectMap.get(findFiledStr));

                }
            }
        });
        return reusltList;
    }

    //根据id找到相应的酒店中文名称
    public List<Map<String, Object>> getHotelName(List<String> idList) {
        List<Map<String, Object>> addList = new ArrayList<>();
        String join = String.join(",", idList);
        RecordSet recordSet = new RecordSet();
        String sql = "select hotelnamezh,holidex,id from uf_hotelinfo where id in (" + join + ")";
        recordSet.execute(sql);
        if (recordSet.next()) {
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("jddm", recordSet.getString("holidex"));
            paramsMap.put("jdmc", recordSet.getString("hotelnamezh"));
            paramsMap.put("zszs", recordSet.getInt("id"));
            addList.add(paramsMap);
        }
        return addList;
    }


    //根据酒店id 值找到所有的 区域，品牌，管理模式
    public Map<String, Object> getHotelNameMap(List<String> idList) {
        Map<String, Object> addMap = new HashMap<>();
        String join = String.join(",", idList);
        RecordSet recordSet = new RecordSet();
        String sql = "select region,brand,id,relationship from uf_hotelinfo where "+ Util.getSubINClause(join,"id","in");
        recordSet.execute(sql);
        while (recordSet.next()) {
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("region", recordSet.getString("region"));
            paramsMap.put("brand", recordSet.getString("brand"));
            paramsMap.put("relationship", recordSet.getString("relationship"));
            paramsMap.put("id", recordSet.getInt("id"));
            addMap.put(recordSet.getInt("id") + "", paramsMap);
        }
        return addMap;
    }

    //根据酒店id 值找到所有的酒店偏好的值创建任务下拉框值，基本信息，任务内容,自动发送，
    public Map<String, Object> getuf_phszList(List<String> idList) {
        Map<String, Object> addMap = new HashMap<>();
        String join = String.join(",", idList);
        RecordSet recordSet = new RecordSet();
        String sql = "select * from uf_phsz where  " + Util.getSubINClause(join,"hotelcode","in") ;
        recordSet.execute(sql);
        while (recordSet.next()) {
            Map<String, Object> paramsMap = new HashMap<>();
            paramsMap.put("cjrw", recordSet.getInt("cjrw"));//创建任务 Check框值
            paramsMap.put("jbxx", recordSet.getInt("jbxx"));//基本信息 Check框值
            paramsMap.put("rwnr", recordSet.getInt("rwnr"));//任务内容 Check框值
            paramsMap.put("zdfs", recordSet.getInt("zdfs"));//自动发送 Check框值
            paramsMap.put("id", recordSet.getInt("id"));
            addMap.put(recordSet.getInt("id") + "", paramsMap);
        }
        return addMap;
    }

    //根据id找到相应的酒店中文代码
    public String getHotelNameholidex(int id) {
        RecordSet recordSet = new RecordSet();
        String sql = "select holidex from uf_hotelinfo where id=?";
        recordSet.executeQuery(sql, id);
        if (recordSet.next()) {
            return recordSet.getString("holidex");
        }
        return "";
    }


}
